﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class TblNguoiDungDAO:IData<TblNguoiDung> 
 	{
		public TblNguoiDungDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref TblNguoiDung item, int t) {
			 return connec.ExecuteNonQuery("sp_TblNguoiDung", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + TblNguoiDung.c_MaNhom, item.MaNhom), new SqlParameter("@" + TblNguoiDung.c_MaNguoiDung, item.MaNguoiDung),
				 new SqlParameter("@" + TblNguoiDung.c_MaDonVi, item.MaDonVi), new SqlParameter("@" + TblNguoiDung.c_TenNguoiDung, item.TenNguoiDung),
				 new SqlParameter("@" + TblNguoiDung.c_Passwd, item.Passwd), new SqlParameter("@" + TblNguoiDung.c_Email, item.Email),
				 new SqlParameter("@" + TblNguoiDung.c_DaXoa, item.DaXoa));
		}

		public override TblNguoiDung GetItem(IDataReader dr)
		{
			TblNguoiDung obj = new TblNguoiDung();
			obj.MaNhom = Convert.ToInt32(dr[TblNguoiDung.c_MaNhom]);
			obj.MaNguoiDung = Convert.ToInt32(dr[TblNguoiDung.c_MaNguoiDung]);
			obj.MaDonVi = Convert.ToInt32(dr[TblNguoiDung.c_MaDonVi]);
			obj.TenNguoiDung = Convert.ToString(dr[TblNguoiDung.c_TenNguoiDung]);
			obj.Passwd = Convert.ToString(dr[TblNguoiDung.c_Passwd]);
			obj.Email = Convert.ToString(dr[TblNguoiDung.c_Email]);
			obj.DaXoa = Convert.ToBoolean(dr[TblNguoiDung.c_DaXoa]);
            obj.TenDonVi = Convert.ToString(dr[TblNguoiDung.c_TenDonVi]);
            obj.TenNhom = Convert.ToString(dr[TblNguoiDung.c_TenNhom]);
			return obj;
		}

		public override List<TblNguoiDung> GetAll()
		{
			return GetAll("sp_GetAllTblNguoiDung", CommandType.StoredProcedure);
		}

		public override TblNguoiDung GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.MaNguoiDung == Convert.ToInt32(id));
		}
		public override TblNguoiDung GetItemById(TblNguoiDung item){
			throw new NotImplementedException();
		}

	}

 }
